package com.powerunion.datacollection.web.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.powerunion.datacollection.service.PendingTaskManager;
import com.powerunion.util.log.LogHelper;

public class PendingTaskAction extends DispatchAction {

	private static final Logger logger = LogHelper.getInstance().getLogger(PendingTaskAction.class);
	private  PendingTaskManager manager = null;
	
	public PendingTaskAction() {
		super();
		this.manager = new PendingTaskManager();
	}
	
	public void finalize() throws Throwable {
		this.manager = null;
		super.finalize();
	}
	
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String userCode = request.getRemoteUser();
		String result = this.manager.findPendingTaskByUser(userCode);
		logger.debug("pendingTask:"+result);
		response.setContentType("text/json;charset=utf-8");
		try{
			response.getWriter().print(result);
		}catch(Exception e) {
			logger.error("输出json失败",e);
			return null;
		}
		return null;
	}
	
}
